package com.taptech.doufu.util;

import com.taptech.doufu.bean.ScreenSplash;

import org.json.JSONException;
import org.json.JSONObject;

public class JsonDataUtil {


	public static ScreenSplash getScreenSplash(JSONObject jsonData) {
		ScreenSplash splash= new ScreenSplash();;

		if (jsonData == null) {
			return splash;
		}

		try {
			if (jsonData.get("data") instanceof JSONObject) {
				JSONObject dataObject = jsonData.getJSONObject("data");

				if (dataObject.has("android_cache_version")) {
					if (dataObject.get("android_cache_version") instanceof String)
						splash.setVersion(dataObject.getInt("android_cache_version"));
				}

				if (dataObject.has("img")) {
					if (dataObject.get("img") instanceof String)
						splash.setUrl(dataObject.getString("img"));
				}

                //点击跳转到广告平台
                if(dataObject.has("ad")){
                    JSONObject tempAd=dataObject.getJSONObject("ad");
                    if((tempAd!=null)&&(tempAd.get("android")!=null) &&(tempAd.get("android") instanceof JSONObject)){
						JSONObject object = tempAd.getJSONObject("android");
						if (object != null) {
							String url = object.getString("url");
							int object_type = object.getInt("object_type");
							int object_id = object.getInt("object_id");
							splash.setSponsoredLink(url);
							splash.setObject_id(object_id);
							splash.setObject_type(object_type);
						}
                    }
                }

			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return splash;

	}




}
